﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coldairarrow.Business.Goods;
using Coldairarrow.Entity.Goods;
using Coldairarrow.Entity.Purchasing;
using Coldairarrow.IBusiness.Purchasing;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;

namespace Coldairarrow.Api.Controllers.backstage
{
    [Route("/backstage/[controller]/[action]")]
    public class BKS_PurchasingController : BaseApiController
    {
        #region DI

        public BKS_PurchasingController(IBTB_GoodsSpecificationsItemBusiness SpecificationsItemBus, IBTB_PurchaseBusiness bTB_PurchaseBusinessBus)
        {
            _SpecificationsItemBus = SpecificationsItemBus;
            _bTB_PurchaseBusinessBus = bTB_PurchaseBusinessBus;
        }
        IBTB_GoodsSpecificationsItemBusiness _SpecificationsItemBus { get; }
        IBTB_PurchaseBusiness _bTB_PurchaseBusinessBus { get; }
        #endregion
        /// <summary>
        /// 预警单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_GoodsSpecificationsItem>> GetDataListAsync(PageInput<BTB_GoodsSpecificationsItem> input)
        {
            return await _SpecificationsItemBus.GetGoodsList(input);
        }
        /// <summary>
        /// 添加或修改采购单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_Purchase data)
        {
            if (data.id.IsNullOrEmpty())
            {
                 InitEntity(data);

                await _bTB_PurchaseBusinessBus.AddDataAsync(data);

            }
            else
            {
                await _bTB_PurchaseBusinessBus.UpdateDataAsync(data);
            }
        }
        ///// <summary>
        ///// 删除采购单
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        [HttpPost]
        public async Task DeleteDataAsync(List<string> ids)
        {
            await _bTB_PurchaseBusinessBus.DeleteDataAsync(ids);
        }
        /// <summary>
        /// 指定查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BTB_Purchase> GetTheDataAsync(string id)
        {
            return await _bTB_PurchaseBusinessBus.GetTheDataAsync(id);
        }
        ///// <summary>
        ///// 采购单
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_Purchase>> GetPurchase(PageInput<BTB_Purchase> input)
        {
            return await _bTB_PurchaseBusinessBus.GetDataList(input);
        }
    }
}
